package com.example.blogsystem.service;

import com.example.blogsystem.mapper.BlogMapper;
import com.example.blogsystem.mapper.UserMapper;
import com.example.blogsystem.model.BlogInfo;
import com.example.blogsystem.model.UserInfo;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private BlogMapper blogMapper;
    public UserInfo getUser(String userName) {
        UserInfo user = userMapper.getUser(userName);
        return user;
    }

    public UserInfo getAuthorById(Integer id) {
        //根据博客id获取作者id
        BlogInfo blogInfo = blogMapper.selectBlogById(id);
        //根据作者id获取作者信息
        if(blogInfo == null || blogInfo.getUserId() == null) {
            return null;
        }
        return userMapper.getAuthorById(blogInfo.getUserId());
    }

    public UserInfo selectUserInfobyId(Integer userId) {
        UserInfo userInfo = userMapper.getUserInfoByid(userId);
        return userInfo;
    }
}
